package learnJava.puzzlers;

public class LoopPuzzlers {
    public static class InTheLoop {
        public static final int END = Integer.MAX_VALUE;
        public static final int START = END - 100;

        public static void main(String[] args) {
            int count = 0;
            // i<=END 永远为真，因为Integer.MAX_VALUE+1 = Integer.MIN_VALUE
            // System.out.println(Integer.MAX_VALUE+1==Integer.MIN_VALUE);
            for (int i = START; i <= END; i++) {
                count++;
            }
            System.out.println(count);
        }
    }

    public static class Shifty {
        public static void main(String[] args) {
            int i = 0;
            // 对int移位会将移位的数对pow(2,5)取余:如 -1<<2 == -1<<34
            // 对long移位会将移位的数对pow(2,6)取余:如 -1<<2 == -1<<66
            // 0xffffffff << 32 == 0x8000 0000 0000 0000
//            System.out.println(-1<<32);
//            System.out.println(-1<<35);
//            System.out.println(-1>>35);
            while (-1 << i != 0)
                i++;
            System.out.println(i);

        }
    }

    public static class Ghost {
        public static void main(String[] args) {
            short i = -1;
            while (i != 0) {
                i >>>= 1; // 这里会先转为int再转为short,所以short永远不变
            }
            System.out.println();
        }
    }

}
